home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 February: Tool Chest / Dev.CD Feb 95 / Dev.CD Feb 95.toast / New System Software Extensions / ASLM SDK v1.1.2 / ASLM Examples / ExampleLibrary / Sources / LibraryManagerTest1.cp < prev    next >
Encoding:
Text File  |  1994-11-21  |  4.1 KB  |  151 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LibraryManagerTest1.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __STDIO__
  12. #include <stdio.h>
  13. #endif
  14.  
  15. #ifndef __EVENTS__
  16. #include <Events.h>
  17. #endif
  18.  
  19. #ifndef __SC__
  20. #ifndef __CURSORCTL__
  21. #include <CursorCtl.h>
  22. #endif
  23. #else
  24. #ifndef __LIBRARYMANAGERUTILITIES__
  25. #include <LibraryManagerUtilities.h>
  26. #endif
  27. #endif
  28.  
  29. #ifndef __EXAMPLECLASS__
  30. #include "ExampleClass.h"
  31. #endif
  32.  
  33. static void Idle(RgnHandle);
  34.  
  35. extern "C" 
  36. void DoTests(TExampleClass* object1, TExampleClass* object2, int count, Boolean trace, Boolean verbose, char* testClassInfoClass)
  37. {
  38.     RgnHandle myRgn;
  39.     unsigned long endTicks, startTicks;
  40.     unsigned long saveCount = count;
  41.  
  42.     InitGraf(&qd.thePort);            // initialize quickdraw so we can use regions
  43.     myRgn = NewRgn();                // a region to use for WaitNextEvent
  44.  
  45. #ifndef __SC__
  46.     InitCursorCtl(NULL);
  47. #endif
  48.  
  49.     if (object1 && object2) 
  50.     {
  51.         startTicks = TickCount();
  52.         object1->SetObjectName("object1");
  53.         object2->SetObjectName("object2");
  54.         
  55.         while (count-- > 0)                 // <-- here is the test while loop
  56.         {                                    // we put calls to DoThisAndThat in here
  57.             object1->DoThisAndThat();        // here we test DoThisAndThat for object1
  58.             object2->DoThisAndThat();        // here we test DoThisAndThat for object2
  59.             if (trace) Idle(myRgn);            // if we are tracing we must idle
  60. #ifndef __SC__
  61.             if (verbose) SpinCursor(1);        // if we are verbose we will spin the cursor
  62. #endif
  63.         }
  64.         
  65.         // test accessing globals
  66.         object1->SetGlobalInt(42);            // set the global using object1
  67.         
  68.         // get the global using object2
  69.         // since object1 and object2 share the same A5 world this will return
  70.         // 42!
  71.         if (verbose)
  72.             printf("%s object2->GetGlobalInt() returns: %d\n",object2->GetObjectName(),object2->GetGlobalInt());
  73.     
  74.         // Test the dynamically linked non-virtual member function GetGlobalRef
  75.         long* theGlobal;
  76.         object1->GetGlobalRef(theGlobal);
  77.         // Now theGlobal is the address of a global variable in the example library, 
  78.         // whose value should still be 42
  79.         if (verbose)
  80.             printf("Address returned by GetGlobalRef is $%x, value is still %d\n", theGlobal, *theGlobal);
  81.         
  82.         endTicks = TickCount();
  83.         if (verbose)
  84.             printf("Dispatches for %d iterations took %d ticks\n", saveCount, endTicks - startTicks);
  85.  
  86.         // Lets try TExampleClass::Test(char*), 
  87.         // note that this is a dynamically linked static member function
  88.         // it will return true since there are 2 instances of TExampleClass
  89.         Boolean hey = TExampleClass::Test("2");
  90.         Boolean hoo = TExampleClass::Test(2);
  91.         Boolean hee = TExampleClass::Test(3);
  92.         if (verbose)
  93.             printf("Three calls to TExampleClass::Test = %s, %s, %s\n",
  94.                 (hey ? "true" : "false"), (hoo ? "true" : "false"), (hee ? "true" : "false"));
  95.     }
  96.  
  97.     if (object1) 
  98.     {
  99.         if (verbose) printf("Disposing object1\n");
  100.         delete object1;
  101.     }
  102.  
  103.     if (object2) {
  104.         if (verbose) printf("Disposing object2\n");
  105.         delete object2;
  106.     }
  107.     
  108.     // Now its time to really do something
  109.     
  110.     if (testClassInfoClass)
  111.     {
  112.         TClassInfo* theInfo = GetLocalLibraryManager()->GetClassInfo(ClassID(testClassInfoClass));
  113.         if (theInfo)
  114.         {
  115.             do
  116.             {
  117.                 char    nameBuffer[256];    // for calls to GetVerboseName
  118.                 printf("\nClass ID:     %s\n", (char*) theInfo->GetClassID());
  119.                 printf("flags:        NewObject(%s) Preload(%s) FunctionSet(%s)\n",
  120.                     theInfo->GetNewObjectFlag() ? "true" : "false",
  121.                     theInfo->GetPreloadFlag() ? "true" : "false",
  122.                     theInfo->GetFunctionSetFlag() ? "true" : "false");
  123.                 printf("version:      Version(%04X) MinVersion(%04X)\n",
  124.                     theInfo->GetVersion(),
  125.                     theInfo->GetMinVersion());
  126.                 if (theInfo->GetLibraryFile())
  127.                     printf("TLibraryFile: %s\n", theInfo->GetLibraryFile()->GetVerboseName(nameBuffer));
  128.                 if (theInfo->GetLibrary())
  129.                     printf("TLibrary:     %s\n", ((TDynamic*)theInfo->GetLibrary())->GetVerboseName(nameBuffer));
  130.                 if (trace)
  131.                 {
  132.                     Trace("\nClass ID: %s\n", (char*) theInfo->GetClassID());
  133.                 }
  134.             } while (theInfo->Next());
  135.             
  136. #ifdef __SC__
  137.             FreeFunctionSetInfo((TFunctionSetInfo*)theInfo);
  138. #else
  139.             delete theInfo;
  140. #endif
  141.         }
  142.     }
  143.     DisposeRgn(myRgn);
  144. }
  145.  
  146. static void Idle(RgnHandle myRgn)
  147. {
  148.     EventRecord myEvent;
  149.     WaitNextEvent(nullEvent, &myEvent, 0, myRgn);
  150. }
  151.